#include<iostream>
using namespace std;
  struct TreeNode {
      int val;
      TreeNode *left;
      TreeNode *right;
      TreeNode() : val(0), left(nullptr), right(nullptr) {}
      TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
      TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
  };
 
class Solution {
public:
    int ans = INT_MAX;
    TreeNode* pre = nullptr;
    void get(TreeNode* root) {
        if (root == nullptr)
            return;
        get(root->left);
        if (pre)
            ans = min(ans, abs(root->val - pre->val));
        pre = root;
        get(root->right);
    }
    int getMinimumDifference(TreeNode* root) {
        get(root);
        return ans;
    }
};